package org.example.entity;

import co.elastic.clients.elasticsearch._types.mapping.Property;
import co.elastic.clients.elasticsearch.indices.IndexSettings;
import co.elastic.clients.elasticsearch.indices.IndexSettingsAnalysis;
import co.elastic.clients.json.JsonData;

import java.util.HashMap;
import java.util.Map;

public class ElasticsearchIndexConfig {

    public static Map<String, Property> getDocxDocumentMapping() {
        Map<String, Property> properties = new HashMap<>();

        // id 字段 - keyword 类型
        properties.put("id", Property.of(b -> b
                .keyword(k -> k)
        ));

        // fileName 字段 - text 类型
        properties.put("fileName", Property.of(b -> b
                .text(t -> t)
        ));

        // content 字段 - 使用 IK 分词器
        properties.put("content", Property.of(b -> b
                .text(t -> t
                        .analyzer("ik_max_word")
                        .searchAnalyzer("ik_smart")
                )
        ));

        // fileSize 字段 - long 类型
        properties.put("fileSize", Property.of(b -> b
                .long_(l -> l)
        ));

        // uploadTime 字段 - long 类型
        properties.put("uploadTime", Property.of(b -> b
                .long_(l -> l)
        ));

        // fileType 字段 - keyword 类型
        properties.put("fileType", Property.of(b -> b
                .keyword(k -> k)
        ));

        return properties;
    }

    public static IndexSettings getDocxDocumentSettings() {
        return IndexSettings.of(b -> b
                .numberOfShards("1")
                .numberOfReplicas("1")
        );
    }
}